import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:photo_frame/router/router_context.dart';

AppBar commonAppBar(
  String? title, {
  bool? hideBack,
  VoidCallback? onBack,
  Widget? leading,
  Widget? titleWidget,
  List<Widget>? actions,
}) {
  return AppBar(
    backgroundColor: Colors.white,
    scrolledUnderElevation: 0.0,
    leadingWidth: 70,
    systemOverlayStyle:
        SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent),
    leading: leading ??
        CupertinoButton(
          onPressed: () {
            if (onBack != null) {
              onBack();
            } else if (hideBack != true) {
              ARouter.instance.pagePop();
            }
            return;
          },
          padding: EdgeInsets.zero,
          child: Visibility(
            visible: hideBack != true,
            child: Padding(
              padding: const EdgeInsets.only(left: 15),
              child: Align(
                alignment: Alignment.centerLeft,
                child: Image.asset(
                  "images/icon_back.png",
                  fit: BoxFit.contain,
                  width: 12,
                  height: 22,
                ),
              ),
            ),
          ),
        ),
    centerTitle: true,
    title: titleWidget ??
        Text(
          title!,
          style: const TextStyle(
            fontSize: 17,
            color: Color(0xff333333),
            fontWeight: FontWeight.bold,
          ),
        ),
    actions: actions,
  );
}

Widget actionTextWidget(String text) {
  return ConstrainedBox(
    constraints: BoxConstraints(
      minWidth: 80.0, // 设置最小宽度为100.0
    ),
    child: Container(
      padding: EdgeInsets.only(left: 8, right: 8),
      alignment: Alignment.center,
      margin: EdgeInsets.only(right: 7.5),
      height: 34,
      // padding: EdgeInsets.symmetric(horizontal: 12),
      decoration: BoxDecoration(
        border: Border.all(
          color: Color(0xff3F74EF),
          width: 1,
        ),
        borderRadius: BorderRadius.circular(22),
      ),
      child: Text(
        text,
        style: TextStyle(color: Color(0xff3F74EF), fontSize: 14),
        strutStyle: const StrutStyle(forceStrutHeight: true),
      ),
    ),
  );
}
